package com.opencee.common.exception;

import com.opencee.common.constants.ResultCode;

import java.util.HashMap;
import java.util.Map;

/**
 * 错误提示异常类
 * http_status = 200
 *
 * @author yadu
 */
public class BaseFailException extends BaseErrorException {

    private static final long serialVersionUID = 4908906410210213271L;
    private Map<String, Object> extra;

    public BaseFailException() {
    }

    public BaseFailException(String msg) {
        super(ResultCode.FAILED.getCode(), msg);
    }

    public BaseFailException(int code, String msg) {
        super(code, msg);
    }

    public BaseFailException(int code, String msg, Throwable cause) {
        super(code, msg, cause);
    }

    public BaseFailException put(String key, Object value) {
        if (this.extra == null) {
            this.extra = new HashMap<>(8);
        }
        this.extra.put(key, value);
        return this;
    }

    public BaseFailException putAll(Map<String, Object> extraData) {
        if (this.extra == null) {
            this.extra = new HashMap<>(8);
        }
        if (extraData != null) {
            this.extra.putAll(extraData);
        }
        return this;
    }

    public Map<String, Object> getExtra() {
        return extra;
    }
}
